/*
import httpInstance2 from "@/utils/filehttp.js";

export function getPileImagesAPI(pileNumber) {
    console.log(pileNumber)
    return httpInstance2({
        url: `file/pileImage?pileNumber=`+pileNumber,
        method: "get",
    });
}
*/

import httpInstance2 from "@/utils/filehttp.js";

export function getPileImagesAPI(pileNumber) {
    console.log(pileNumber)
    return httpInstance2({
        url: `file/pileImage?pileNumber=`+pileNumber,
        method: "get",
    });
}

// 新增：支持进度回调的文件上传API
export function uploadPileImageAPI(formData, onUploadProgress) {
    return httpInstance2({
        url: 'file/upload', // 假设的上传URL，需根据实际后端API调整
        method: 'POST',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        // 添加进度事件处理
        onUploadProgress: (progressEvent) => {
            if (progressEvent.lengthComputable) {
                // 计算上传百分比并触发回调
                const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
                console.log(`上传进度: ${percentCompleted}%`);
                // 调用传入的回调函数
                if (typeof onUploadProgress === 'function') {
                    onUploadProgress(progressEvent);
                }
            }
        }
    });
}
// DELETE http://localhost:8081/file/deleteInformation?pileNumber=43-1&userId=1
/**
 *
 * @param pileNumber
 * @param userId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function deleteInformationAPI(pileNumber,userId) {
    return httpInstance2({
        url: 'file/deleteInformation', // 假设的上传URL，需根据实际后端API调整
        method: 'DElETE',
        params: {pileNumber,userId},
    });
}
// DELETE http://localhost:8081/file/deleteImage?fileId={{$random.integer(100)}}&userId={{$random.integer(100)}}
/**
 *
 * @param fileId
 * @param userId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function deleteImageAPI(fileId,userId) {
    return httpInstance2({
        url: 'file/deleteImage', // 假设的上传URL，需根据实际后端API调整
        method: 'DElETE',
        params: {fileId,userId},
    });
}
